<script>
    import { onMount } from 'svelte'
    import {location, querystring} from 'svelte-spa-router'
    import Detail from '../components/detail.svelte';

    import { Post } from '../lib/net.js';
    import { OrderDetail } from '../api.js';
    import { OrderType,CoinType } from '../conf.js';

    let data = {list:[]};
    let map_type = ["充值", "提币", "划转", "划转", "盈利",  "赔付" ];
    let map_state = ["委托中","持仓中","用户平仓","系统强制平仓"];

    onMount(async ()=>{
       let tid = $querystring.replace("tid=","");
       let ret = await Post(OrderDetail,{tid});
       console.log(ret);
        console.log('ret');

       let symbol = "";
       if(ret.type == 0 || ret.type == 4) {
        data.color = "green"
        symbol = "+";
       }
       if(ret.type == 1 || ret.type == 5) {
        data.color = "red"
        symbol = "-";
       }

       data.title = "";
       data.subtitle = "";

       data.list = [
        {key: "用户UID",val: ret.user.id},
        {key: "姓名",val: ret.user_info.name || "--"},
        {key: "手机号",val: ret.user.phone || "--"},
        {key: "币种",val: CoinType[ret.order.coin_type].toUpperCase()},
        {key: "张数",val: ret.order.count},
        {key: "占用保证金",val: ret.order.promise},
        {key: "开仓类型",val: OrderType[ret.order.buy_type]},
        {key: "杠杆",val: ret.order.multiple},
        {key: "状态",val: map_state[ret.order.state]},
        {key: "开仓点位",val: ret.order.open},
        {key: "平仓时间",val: ret.order.show_delivery_date},
        {key: "盈亏比例",val: (ret.order.signed ? "+" : "-") + (ret.order.income/ret.order.promise).toFixed(2) + "%"  || "--"},
        {key: "止损设置",val: ret.order.low || "--"},
        {key: "止盈设置",val: ret.order.high || "--"},
       ]
    });

</script>

<div class="container">
    <Detail data={data}/>
</div>

<style>
    .container {
        margin-top:10px;
        background-color: #fff;
        padding-left: 100px;
    }
</style>
